@extends('departmentManagement.project.layouts')
@section('style')
    <meta name="_token" content="{{ csrf_token() }}"/>
    <style>
        .process-index-th{
            text-align: center;
            color: #676767;
        }
        .process-index-td{
            text-align: center;
            color: #676767;
        }
        .ico_img{
            width: 85px;
            height: 80px;
            margin-top: -20px;
        }
    </style>
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap-datetimepicker.min.css')}}">
    <link rel="stylesheet" href="{{asset('admin_assets/css/pretty.min.css')}}">
    <link async rel="stylesheet" href="https://cdn.materialdesignicons.com/1.8.36/css/materialdesignicons.min.css"/>
    <link rel="stylesheet" type="text/css" href="{{asset('admin_assets/css/fileinput.min.css')}}">
    <link rel="stylesheet" href="{{url('css/search.css')}}">
@stop
@section('content')
    <div class="content-wrapper" style="background-color: white">
        <section id="list" class="content">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="box box-info"
                         style="padding-top: 0px;margin-top: 0px;border-top: 0px;border-bottom: solid 1px #0080ff;">
                        <div class="box-body" style="">
                            <div class="row">
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="margin-top: 0.5vw">
                                    <a href="#" title="返回首页" style="float: left"><i class="fa fa-home fa-2x"
                                                                                    style="width: 100%;color: #0080FF">
                                        </i></a>
                                    <a href="{{url('management/project/index')}}"><span
                                                style="font-size: 18px;float: left;margin-top: 5px">&nbsp;首页</span></a>
                                    <div class="clear"></div>
                                </div>
                                {{--<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12  col-lg-offset-8 col-md-offset-8">--}}
                                    {{--<form action="{{url('management/project/indexSearch')}}" method="post" enctype="multipart/form-data" class="search">--}}
                                        {{--{{csrf_field()}}--}}
                                        {{--<button class="fa fa-search fa-lg"></button>--}}
                                        {{--<input class="search" type="search" id="search-input" name="search" value="{{$keywords}}">--}}
                                    {{--</form>--}}
                                {{--</div>--}}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="small-box bg-aqua">
                        <div class="inner">
                            <h3>{{$processNum['total']}}</h3>
                            <p>业务总数</p>
                        </div>
                        <div class="icon">
                            <img class="ico_img" src="{{asset('admin_assets/img/total_icon.png')}}">
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="small-box bg-yellow ">
                        <div class="inner">
                            <h3>{{$processNum['processing']}}</h3>
                            <p>处理中</p>
                        </div>
                        <div class="icon">
                            <img class="ico_img" src="{{asset('admin_assets/img/dealing_icon.png')}}">
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="small-box  bg-red">
                        <div class="inner">
                            <h3>{{$processNum['not_begin']}}</h3>
                            <p>未开始</p>
                        </div>
                        <div class="icon">
                            <img class="ico_img" src="{{asset('admin_assets/img/nobegin_icon.png')}}">
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="small-box bg-green">
                        <div class="inner">
                            <h3>{{$processNum['completed']}}</h3>
                            <p>已完成</p>
                        </div>
                        <div class="icon">
                            <img class="ico_img" src="{{asset('admin_assets/img/finish_icon.png')}}">
                        </div>
                    </div>
                </div>
            </div>
            @include('public/alert')
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th class="process-index-th">编号</th>
                                <th class="process-index-th">公司</th>
                                <th class="process-index-th">任务类别</th>
                                <th class="process-index-th">类型</th>
                                <th class="process-index-th">名称</th>
                                <th class="process-index-th">申请人</th>
                                <th class="process-index-th">联系电话</th>
                                <th class="process-index-th">申请日期</th>
                                <th class="process-index-th">款项金额</th>
                                <th class="process-index-th">尾款金额</th>
                                <th class="process-index-th">进度</th>
                                <th class="process-index-th">报件资料</th>
                                <th class="process-index-th">操作</th>
                            </tr>
                            </thead>
                            <tbody>


                            @if(!empty($project))
                                @foreach($project as $key => $value)

                                    <tr>

                                        <td class="process-index-td">{{$key+1}}</td>
                                        <td class="process-index-td company">{{$value['Product']['company']}}</td>
                                        <td class="process-index-td is_renew">
                                            @if($value['is_renew']==0)
                                                首次任务
                                            @else
                                                续费任务
                                            @endif
                                        </td>
                                        <td class="process-index-td name">{{$value['FirstType']['name']}}</td>
                                        <td class="process-index-td product_name">{{$value['product']['name']}}</td>
                                        <td class="process-index-td applicant">{{$value['product']['applicant']}}</td>
                                        <td class="process-index-td phone">{{$value['product']['phone']}}</td>
                                        <td class="process-index-td">{{date("Y-m-d",strtotime($value['created_at']))}}</td>
                                        <td class="process-index-td">¥{{$value['price']}}</td>
                                        <td class="process-index-td">¥{{$value['tail_payment']}}</td>
                                        <td class="process-index-td" >
                                            @if(empty($value['ProgressList']))
                                                已认领，等待处理
                                            @else
                                                {{$value['ProgressList']['name']}}
                                            @endif
                                        </td>
                                        <td class="process-index-td">
                                            @if(empty($value['Product']['file']))
                                                未上传
                                            @else
                                                <a target="_blank" href="{{route("management.project.downloadFile",["product_id"=>$value['Product']['id']])}}" class="download-file">点击审阅</a>
                                            @endif
                                        </td>
                                        <td class="process-index-td">
                                            @if($value['is_cancel']==1)
                                                <a target="_blank" href="{{route('management.project.productDetail',["product_id"=>$value['product_id']])}}">查看详情</a>
                                                <a href="#" class="uploadOfficalFile" data-toggle="modal"
                                                   data-product_id="{{$value['product']['id']}}"
                                                   data-target="#modal-official-document">官方文件</a>


                                                <a href="#" class="update-process"
                                                   data-toggle="modal"
                                                   data-process_id="{{$value['id']}}"
                                                   data-process="{{$value['Progress']}}"
                                                   data-is_renew="{{$value['is_renew']}}"
                                                   data-product_name="{{$value['product']['name']}}"
                                                   data-product_number="{{$value['product']['number']}}"
                                                   data-is_push="{{$value['is_push']}}"
                                                   data-progress_list_id="{{$value['progress_list_id']}}"
                                                   data-registration_area="{{$value['product']['registration_area']}}"
                                                   data-registration_time="{{$value['product']['registration_time']}}"
                                                   data-authority_time="{{$value['product']['authority_time']}}"
                                                   data-is_end_money="{{$value['urge']}}"
                                                   data-target="#modal-project-update-progress">更新进度</a>
                                            @else
                                                <span style="cursor: pointer">查看详情</span>
                                                <span style="cursor: pointer">官方文件</span>
                                                <span style="cursor: pointer">更新进度</span>
                                            @endif


                                        </td>
                                    </tr>

                                @endforeach
                            @else
                                <tr>
                                    <td class="process-claim-td" colspan="12" ><h3 align="center">暂无数据</h3></td>
                                </tr>

                            @endif
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>
    </div>
    @include('public/project-update-progressModal')
    @include('public/official-documentModal')
@stop
@section('javascript')
    <script src="{{asset('admin_assets/js/fileinput.min.js')}}"></script>
    <script src="{{asset('admin_assets/js/fileinput_locale_zh.js')}}"></script>
    <script src="{{asset('admin_assets/js/bootstrap-datetimepicker.min.js')}}"></script>
    <script src="{{asset('js/list.min.js')}}"></script>
    <script>
        $(".form_datetime").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true,
            todayBtn: true,
            minuteStep: 10,
            language: "en"
        });
        $("#inputFile").fileinput({
            language: 'zh',
            autoReplace: false,
            maxFileCount: 1,
            allowedFileExtensions: ["jpg", "png", "gif", "pdf"],
            browseClass: "btn btn-primary",
            showUpload: false,
            showCancel: true,
            previewFileIcon: "<i class='fa fa-upload'></i>"
        });

        $(".update-process").click(function () {
            var process_list=$(this).attr("data-process");
            var process_id=$(this).attr("data-process_id");
            var is_push=$(this).attr("data-is_push");
            var product_name=$(this).attr("data-product_name");
            var product_number=$(this).attr("data-product_number");
            var progress_list_id=$(this).attr("data-progress_list_id");
            var registration_area=$(this).attr("data-registration_area");
            var registration_time=$(this).attr("data-registration_time");
            var authority_time = $(this).attr("data-authority_time");
            var is_end_money=$(this).attr("data-is_end_money");
            process_list=JSON.parse(process_list);
            var optionlist="<option value='' disabled selected=\"selected\" >请选择进度</option>";
            $.each(process_list,function (key,value) {
                optionlist=optionlist+"<option value='"+value.id+"'>"+value.name+"</option>"
            });
            $("#progress").html(optionlist);
            $("#progress").val(progress_list_id);
            $("#process_id").val(process_id);
            $("#name").val(product_name);
            $("#product_number").val(product_number);
            $("#registration_area").val(registration_area);
            $("#registration_time").val(registration_time);
            $("#authority_time").val(authority_time);
            if(is_push!="0"){
                $("#is_push").prop('checked',true);
            }else{
                $("#is_push").prop('checked',false);
            }
            if(is_end_money!="0"){
                $("#is_end_money").prop('checked',true);
            }else{
                $("#is_end_money").prop('checked',false);
            }
        });



        $("#update_progress").click(function () {
            var process_list=$("#progress").val();
            var process_id=$("#process_id").val();
            var name=  $("#name").val();
            var product_number= $("#product_number").val();
            var is_push= $("#is_push").is(':checked');
            var is_end_money=$("#is_end_money").is(':checked');
            var text= $("#progress").find("option:selected").text();
            var registration_area= $("#registration_area").val();
            var registration_time= $("#registration_time").val();
            var authority_time = $("#authority_time").val();
            var formData = new FormData();
            formData.append("process_id" , process_id);
            formData.append("process_list_id" , process_list);
            formData.append("content" , text);
            formData.append("name" , name);
            formData.append("product_number" , product_number);
            formData.append("is_push" , is_push);
            formData.append("registration_area" , registration_area);
            formData.append("registration_time" , registration_time);
            formData.append("is_end_money" , is_end_money);
            formData.append("authority_time", authority_time);
            $.ajax({
                url:'{{route("management.project.updateProgress")}}',
                data: formData,
                processData : false,
                contentType : false ,
                type:'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success:function (data) {
                    console.log(data);
                    $returnData=JSON.parse(data);
                    alert($returnData.message);
                    window.location.reload();
                },
                error:function (data) {
                    alert("更新任务进度失败");
                    window.location.reload();
                }
            });
        });


        $(".uploadOfficalFile").click(function () {
            var product_id=$(this).attr("data-product_id");
            $("#product_id").val(product_id);
        });



        $("#update_progress_btn").click(function () {
            var url="{{route("management.project.uploadFile")}}";
            var filename=$("#filename").val();
            var product_id=$("#product_id").val();
            var inputFile=$("#inputFile").get(0).files[0];
            var formData = new FormData($("#upfrom")[0]);
//            formData.append("filename" , filename);
//            formData.append("file" , inputFile);
//            formData.append("product_id" , product_id);
            $.ajax({
                url:url,
                data: formData,
                processData : false,
                contentType : false ,
                type:'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success:function (data) {
                    $returnData=JSON.parse(data);
                    alert($returnData.message);
                    console.log($returnData.data);
                    window.location.reload();
                },
                error:function (data) {
                    alert("上传文件失败");
                    window.location.reload();
                }
            });


        });


    </script>

    <script>
        var options = {
            valueNames: ['applicant',"name","product_name","company","progressList", 'is_renew','firstType','created_at','product_state','product_level','agent',"phone"]
        };
        var List = new List('list', options);
        List.search($('#search-input').val());
        $(".form_datetime").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true,
            todayBtn: true,
            minuteStep: 10,
            language: "en"
        });
    </script>
@stop
